package com.yenlien.traceyun.control.entity;

import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author jialong
 * @date 2021/05/19
 * @description: 存放在货架里的货物
 **/
@Data
@Entity
@Table(name = "goods")
public class Goods implements Serializable {
    private static final long serialVersionUID = 4464020260002734891L;

    // 主键ID
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    //  货架ID
    @Column
    @NotNull(message = "货架ID不能为空")
    private Long shelvesId;

    private String companyId;

    // 货物名称
    @Column
    @NotBlank(message = "货物名称不能为空")
    private String goodsName;

    // 存货量
    @Column
    @NotNull(message = "存货量不能为空")
    private Integer goodsNum;

    // 货物估值
    @Column
    @NotBlank(message = "货物估值不能为空")
    private String goodsValue;

    // 货物品级ID
    @Column
    @NotNull(message = "货物品级ID不能为空")
    private Long goodsLevel;

    @Transient
    private String goodsLevelName;

    // 货主名称
    @Column
    @NotBlank(message = "货主名称不能为空")
    private String ownerName;

    // 存货类型 （1=存放，2=抵押）
    @Column
    @NotBlank(message = "存货类型 （1=存放，2=抵押）不能为空")
    private String type;

    // 入库批次号
    @Column
    private String batch;

    // 种植批次号
    @Column
    private String plantBatch;

    // 保质期（单位为天）
    @Column
    @NotBlank(message = "保质期（单位为天）不能为空")
    private String expiration;

    @Column
    private LocalDateTime createTime = LocalDateTime.now();

    @Transient
    private int page = 1;
    @Transient
    private int pageSize = 10;

    public int getPage() {
        if (this.page > 0) {
            return page - 1;
        } else {
            return 0;
        }
    }
}
